Skip to content

Conversation

@xezon
Copy link

@xezon xezon commented Dec 2, 2025

Merge with Rebase

The first commit applies a bit of refactoring to WinMain and Mouse because there is some chaos.

The second commit prevents the cursor capture when the mouse is outside of the app window. This avoid inconcienences when grapping the top window bar to move the window. Also it acts more graceful this way no longer teleporting the cursor into the game window when focus is regained. The user now can move his cursor back into the window before it is recaptured.

TODO

  • Replicated in Generals
  • Add pull id to commits

@xezon xezon added this to the Important features milestone Dec 2, 2025
@xezon xezon added Bug Something is not working right, typically is user facing Minor Severity: Minor < Major < Critical < Blocker ThisProject The issue was introduced by this project, or this task is specific to this project Input labels Dec 2, 2025
Copy link

@Skyaero42 Skyaero42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, this fixes the problem.

@xezon xezon force-pushed the xezon/fix-cursor-capture branch from aa9904c to ca4c963 Compare December 7, 2025 09:43
@xezon
Copy link
Author

xezon commented Dec 7, 2025

Now also renamed the onResolutionChanged function in HeaderTemplate class to be consistent with Mouse.

Replicated in Generals with conflicts in WinMain.cpp

$ git diff d81e7435dfc6b695adefca31df87749a6ef3ca5c..6aefa49f05d21e0d00d891ba94d4272e0a7365d1 > changes.patch

$ git apply -p2 --directory=Generals --reject --whitespace=fix changes.patch
Checking patch Generals/Code/GameEngine/Include/GameClient/Mouse.h...
Checking patch Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp...
Hunk #1 succeeded at 709 (offset -37 lines).
Checking patch Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp...
Hunk #1 succeeded at 1541 (offset -60 lines).
Checking patch Generals/Code/GameEngine/Source/GameClient/Input/Mouse.cpp...
Checking patch Generals/Code/Main/WinMain.cpp...
Hunk #1 succeeded at 69 (offset -3 lines).
error: while searching for:
                        //-------------------------------------------------------------------------
                        case WM_NCHITTEST:
                        // Prevent the user from selecting the menu in fullscreen mode
            if( !TheGlobalData->m_windowed )
                return HTCLIENT;
            break;

                        //-------------------------------------------------------------------------
                        case WM_POWERBROADCAST:
            switch( wParam )
            {
                #ifndef PBT_APMQUERYSUSPEND
                    #define PBT_APMQUERYSUSPEND 0x0000
                #endif
                case PBT_APMQUERYSUSPEND:
                    // At this point, the app should save any data for open
                    // network connections, files, etc., and prepare to go into
                    // a suspended mode.
                    return TRUE;

                #ifndef PBT_APMRESUMESUSPEND
                    #define PBT_APMRESUMESUSPEND 0x0007
                #endif
                case PBT_APMRESUMESUSPEND:
                    // At this point, the app should recover any data, network
                    // connections, files, etc., and resume running from when
                    // the app was suspended.
                    return TRUE;
            }
            break;
                        //-------------------------------------------------------------------------
                        case WM_SYSCOMMAND:
            // Prevent moving/sizing and power loss in fullscreen mode
            switch( wParam )
            {
                case SC_KEYMENU:
                    // TheSuperHackers @bugfix Mauller 10/05/2025 Always handle this command to prevent halting the game when left Alt is pressed.
                    return 1;
                case SC_MOVE:
                case SC_SIZE:
                case SC_MAXIMIZE:
                case SC_MONITORPOWER:
                    if( !TheGlobalData->m_windowed )
                        return 1;
                    break;
            }
            break;

                        case WM_QUERYENDSESSION:
                        {

error: patch failed: Generals/Code/Main/WinMain.cpp:319
error: while searching for:

                        // ------------------------------------------------------------------------
                        case WM_CLOSE:
                        if (!TheGameEngine->getQuitting())
                        {
                                //user is exiting without using the menus

                                //This method didn't work in cinematics because we don't process messages.
                                //But it's the cleanest way to exit that's similar to using menus.
                                TheMessageStream->appendMessage(GameMessage::MSG_META_DEMO_INSTANT_QUIT);

                                //This method used to disable quitting.  We just put up the options screen instead.
                                //TheMessageStream->appendMessage(GameMessage::MSG_META_OPTIONS);

                                //This method works everywhere but isn't as clean at shutting down.
                                //TheGameEngine->checkAbnormalQuitting();       //old way to log disconnections for ALT-F4
                                //TheGameEngine->reset();
                                //TheGameEngine->setQuitting(TRUE);
                                //_exit(EXIT_SUCCESS);
                                return 0;
                        }

                        // ------------------------------------------------------------------------
                        case WM_SETFOCUS:
                        {

                                //
                                // reset the state of our keyboard cause we haven't been paying
                                // attention to the keys while focus was away
                                //
                                if( TheKeyboard )
                                        TheKeyboard->resetKeys();

                                if (TheMouse)
                                        TheMouse->regainFocus();

                                break;

                        }

                        //-------------------------------------------------------------------------
                        case WM_MOVE:

error: patch failed: Generals/Code/Main/WinMain.cpp:372
Hunk #4 succeeded at 409 (offset -4 lines).
Hunk #5 succeeded at 455 (offset -4 lines).
Hunk #6 succeeded at 484 (offset -4 lines).
Hunk #7 succeeded at 493 (offset -4 lines).
Hunk #8 succeeded at 515 (offset -4 lines).
Hunk #9 succeeded at 536 (offset -4 lines).
Applied patch Generals/Code/GameEngine/Include/GameClient/Mouse.h cleanly.
Applied patch Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp cleanly.
Applied patch Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp cleanly.
Applied patch Generals/Code/GameEngine/Source/GameClient/Input/Mouse.cpp cleanly.
Applying patch Generals/Code/Main/WinMain.cpp with 2 rejects...
Hunk #1 applied cleanly.
Rejected hunk #2.
Rejected hunk #3.
Hunk #4 applied cleanly.
Hunk #5 applied cleanly.
Hunk #6 applied cleanly.
Hunk #7 applied cleanly.
Hunk #8 applied cleanly.
Hunk #9 applied cleanly.

$ git diff 6aefa49f05d21e0d00d891ba94d4272e0a7365d1..e36ccde45203091746275cfc31c6b1e7d71e720a > changes.patch

$ git apply -p2 --directory=Generals --reject --whitespace=fix changes.patch                           Checking patch Generals/Code/GameEngine/Include/GameClient/Mouse.h...
Checking patch Generals/Code/GameEngine/Source/GameClient/Input/Mouse.cpp...
Checking patch Generals/Code/Main/WinMain.cpp...
Hunk #1 succeeded at 413 (offset -23 lines).
Hunk #2 succeeded at 534 (offset -23 lines).
Hunk #3 succeeded at 545 (offset -23 lines).
Applied patch Generals/Code/GameEngine/Include/GameClient/Mouse.h cleanly.
Applied patch Generals/Code/GameEngine/Source/GameClient/Input/Mouse.cpp cleanly.
Applied patch Generals/Code/Main/WinMain.cpp cleanly.

@xezon xezon merged commit 68d832f into TheSuperHackers:main Dec 7, 2025
25 checks passed
xezon added a commit that referenced this pull request Dec 7, 2025
@xezon xezon deleted the xezon/fix-cursor-capture branch December 7, 2025 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something is not working right, typically is user facing Input Minor Severity: Minor < Major < Critical < Blocker ThisProject The issue was introduced by this project, or this task is specific to this project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to move window when cursor capture is enabled

2 participants